package itsos.service.impl;

import java.sql.*;
import java.util.List;

import javax.servlet.http.*;

import org.springframework.web.servlet.ModelAndView;

import itsos.dao.*;
import itsos.model.*;
import itsos.service.*;
import itsos.common.*;

public class MemberServiceImpl implements MemberService {

	private MemberDao memberDao;
	
	public void setMemberDao(MemberDao memberDao)
	{
		this.memberDao = memberDao;
	}
	
	
	public boolean addUser(HttpServletRequest request)
	{
				
		Member member = new Member();
		Member member2 = new Member();
				
		
		member.setLoginID(request.getParameter("loginID"));
		member.setMemberName(request.getParameter("memberName"));
		member.setPassword(request.getParameter("password"));
		member.setMemberDesc(request.getParameter("memberDesc"));
		member.setEmail(request.getParameter("email"));
		member.setInsertTime(new Timestamp(System.currentTimeMillis()));
		member.setUpdateTime(new Timestamp(System.currentTimeMillis()));
		member.setInsertUserID(ConstCode.SUPER_ADMIN_NUMBER);
		member.setUpdateUserID(ConstCode.SUPER_ADMIN_NUMBER);
		member.setDeleteFlag("N");
		member.setMemberGroup(ConstCode.GENEREL);
		
		member2 = memberDao.getUserName2(member.getLoginID());
		
		if(!(member2==null))
		{
			return false;
		}
		
		
		memberDao.insertMember(member);
						
		return true;
	}


	public Member getMember(HttpServletRequest request, HttpSession session) {
		
		Member member = new Member();
		
		member = memberDao.getMember((Long)session.getAttribute("memberID"));
		
		return member;
	}


	public void updateMember(HttpServletRequest request, HttpSession session) {
		
		Member member = new Member();
		
		member.setMemberID((Long)session.getAttribute("memberID"));
		member.setMemberName(request.getParameter("memberName"));
		member.setPassword(request.getParameter("password"));
		member.setMemberDesc(request.getParameter("memberDesc"));
		member.setEmail(request.getParameter("email"));
		member.setUpdateTime(new Timestamp(System.currentTimeMillis()));
		member.setUpdateUserID(member.getMemberID());
		
		memberDao.updateMember(member);
	}
	
	
	public void deleteMemberByMemberID(HttpServletRequest request)
	{
		Member member = new Member();
		member.setMemberID(new Long(Long.parseLong(request.getParameter("memberID"))));
		member.setDeleteFlag(request.getParameter("deleteFlag"));
		
		memberDao.deleteMember(member);
	}

	public void deleteMemberBySession(HttpServletRequest request, HttpSession session)
	{
		Member member = new Member();
		member.setMemberID((Long)session.getAttribute("memberID"));
		member.setDeleteFlag(request.getParameter("deleteFlag"));
		
		memberDao.deleteMember(member);
	}
	
	public List getLoginID()
	{
		
		return memberDao.getLoginID();
	}


	public void saveGroup(HttpServletRequest request) {
		
		Member member = new Member();
		member.setLoginID(request.getParameter("loginID"));
		member.setMemberGroup(new Long(Long.parseLong(request.getParameter("memberGroup"))));
		member.setUpdateTime(new Timestamp(System.currentTimeMillis()));
		member.setUpdateUserID(ConstCode.SUPER_ADMIN_NUMBER);
		
		memberDao.saveGroup(member);
		
	}


	public List selectAdmin() {
		
		return memberDao.adminSelect();
	}


	public List devMember() {

		List list = memberDao.devMember();
			
		return list;
	}
	
}
